<template>
    <div class="detailBox">
        <!---详情--->
        <div class="dtItemBox dtItemBox2">
            <div class="navBox">
                <div class="title">
                    <bar-title title="长势记录详情" style="background: none;" />
                </div>
                <el-icon @click="close(2)" size="18px" color="#999999">
                    <Close />
                </el-icon>
            </div>
            <div class="dtMainCon dtMainCon2" v-if="!openImage">
                <div class="scroll-box">
                <template v-for="details in list">
                        <div style="border-bottom: 2px solid #ddd;padding:10px 0;">
                            <div class="drtqBox">
                                <div class="wd">
                                    <p>当前天气</p>
                                    <h4 style="font-size: 16px;">{{ details.farmTianqi }}</h4>
                                </div>
                            </div>
                            <ul class="tastItemList">
                                <li><label>记录时间：</label>{{ details.operationTime }}{{ dateToWeek(details.operationTime) }}</li>
                            </ul>
                            <ul class="tastItemList">
                                <li><label>生育时期：</label><span style="color:#FFBB4F;">{{ details.shengyuqiName }}</span></li>
                            </ul>
                            <ul class="tastItemList">
                                <li><label>长势状况：</label>
                                    <span class="tags" :style="`color: ${details.growthColor};border:1px solid ${details.growthColor}`" 
                                    :class="details.stageTaskXuntianCode">{{ details.growthName }}</span>
                                </li>
                            </ul>
                            <ul class="tastItemList">
                                <li><label>上传时间：</label>{{ details.operationTime }}{{ dateToWeek(details.operationTime) }}</li>
                            </ul>
                            <div class="imgBox">
                                <template v-if="details.pictures">
                                    <template v-for="o in JSON.parse(details.pictures.replace(/\\/g, ''))">
                                        <template  v-if="o.url.includes('.png')||o.url.includes('.jpg') ||o.url.includes('.jpeg') ">
                                            <div style="margin-bottom: 2px;">
                                                <!-- <imageView  :src="o.url" :list="[o.url]" /> -->
                                                <img :src="o.url" style="width:100%;height:100%;" @click="btnOpenList(details)" />
                                            </div>
                                        </template>
                                    <div v-else style="width: 100%;margin-bottom: 10px;">
                                        <video controls style="width: 100%;">
                                            <source :src="`${o.url}`">
                                            您的浏览器不支持 audio 元素。
                                        </video>
                                </div>
                                </template>
                                </template>
                            </div>
                            <div style="text-align: center;">
                                <vxe-button mode="text" @click="btnOpenList(details)" status="primary" content="查看备注"></vxe-button>
                            </div>
                            <div style="width: 100%; margin-bottom: 10px;" v-if="details.voice">
                                <template v-for="dt in JSON.parse(details.voice)">
                                    <audio controls style="width: 100%;">
                                        <source :src="`${dt.url}`" type="audio/mpeg">
                                        您的浏览器不支持 audio 元素。
                                    </audio>
                                </template>
                            </div>
                            <div style="width: 100%; margin-bottom: 10px;" v-if="details.video">
                                <template v-for="dt in JSON.parse(details.video)">
                                    <video controls style="width: 100%;">
                                        <source :src="`${dt.url}`">
                                        您的浏览器不支持 audio 元素。
                                    </video>
                                </template>
                            </div>
                            <ul class="tastItemList">
                                <!-- <li><label>记录地块：</label>{{ details.operationAddress }}</li> -->
                                <li><label>记录地块：</label>{{ details.landCount }} 地块、{{ details.landArea }}亩</li>
                            </ul>
                            <ul class="tastItemList">
                                <li><label>记录人：</label>{{ details.createName }}</li>
                            </ul>
                        </div>
                    </template>
                </div>
            </div>
            <div v-else>
                {{details?.description||'' }}
            </div>
            <vxe-modal v-model="openImage" 
                       title="查看图片" 
                       :draggable="false"
                        show-close :mask="false" 
                        width="800" 
                        height="570">
                            <template #default>
                                <el-carousel :interval="5000" :autoplay="false" arrow="always" height="500px">
                                        <template v-if="itemInfo.pictures">
                                            <template v-for="o in JSON.parse(itemInfo.pictures.replace(/\\/g, ''))">
                                                <template  v-if="o.url.includes('.png')||o.url.includes('.jpg') ||o.url.includes('.jpeg') ">
                                                    <el-carousel-item>
                                                        <div style="height:500px;">
                                                            <imageView  :src="o.url" :list="[o.url]" />
                                                    </div>
                                                    </el-carousel-item>
                                                </template>
                                        </template>
                                        </template>
                                    </el-carousel>
                            </template>
            </vxe-modal>
        </div>
    </div>
</template>

<script setup>
import { ref,nextTick} from 'vue'
import barTitle from '@/view/produceManage/record/components/barTitle.vue'
import imageView from '@/components/custom/image.vue'
import { formatDate, dateToWeek } from '@/utils/format.js'
const props = defineProps({
    list: {
        type:Array,
        default:[]
    }
})

const emit = defineEmits(['close'])
const openImage = ref(false)
const itemInfo = ref({})

const close = () => {
    emit('close')
}
const btnOpenList = (item) => {
    itemInfo.value = item
    openImage.value = true
}

</script>

<style lang="scss" scoped>
.detailBox {
    display: flex;
    flex-flow: column;
    box-sizing: border-box;
    position: absolute;
    z-index: 2002;
    right: 10px;
    top: 10px;
    width: 300px;
    padding: 0;
    height: calc(100vh - 95px);

    .dtItemBox {
        display: flex;
        flex-flow: column;
        box-sizing: border-box;
        width: 100%;
        background: #FFFFFF;
        border-radius: 2px;
        //height: calc(100vh - 200px);
        padding: 10px;
        padding-top: 0;
        flex-shrink: 0;

        &.dtItemBox2 {
            flex: 1;
            flex-shrink: 0;
            height: 0; // 才会有滚动条
        }

        &+.dtItemBox {
            margin-top: 10px;
        }

        .navBox {
            display: flex;
            align-items: center;
            border-bottom: 1px solid #F4F4F4;

            .title {
                flex: 1;
            }

            .el-icon {
                cursor: pointer;

                &:hover {
                    color: #04AE70;
                }
            }
        }

        .dtMainCon {
            max-height: 211px;
            overflow: hidden;
            overflow-y: auto;

            &.dtMainCon2 {
                max-height: none;
                flex: 1;
                flex-shrink: 0;
                // max-height: calc(100vh - 431px) 
            }

            .scroll-box {
                height: 100%;
                overflow: hidden;
                overflow-y: auto;
            }

            .landList {
                list-style: none;
                padding: 0;
                margin: 0;

                li {
                    background: rgba(0, 175, 112, 0.05);
                    border-radius: 2px;
                    overflow: hidden;
                   cursor: pointer;
                    &+li {
                        margin-top: 10px;
                    }

                    .liCon {
                        padding: 10px;

                        p {
                            display: flex;
                            align-items: center;
                            height: 22px;
                            font-size: 14px;
                            font-family: PingFangSC, PingFang SC;
                            font-weight: 500;
                            color: #333333;

                            img {
                                display: block;
                                height: 18px;
                                margin: 0 5px 0 0;
                            }

                            span {
                                color: #858786;
                            }
                        }
                    }
                }
            }

            .subTitle {
                display: flex;
                align-items: center;
                height: 36px;
                background: rgba(0, 175, 112, 0.1);
                border-radius: 2px 2px 0px 0px;
                padding: 0 10px;

                &::before {
                    content: '';
                    display: block;
                    width: 6px;
                    height: 6px;
                    background-color: #00B070;
                    margin: 0 8px 0 0;
                }

                label {
                    flex: 1;
                    font-size: 14px;
                    font-family: PingFangSC, PingFang SC;
                    font-weight: 600;
                    color: #00B070;

                }

                span {
                    font-size: 14px;
                    font-family: PingFangSC, PingFang SC;
                    font-weight: 500;
                    color: #333333;
                }
            }

            .drtqBox {
                display: flex;
                box-sizing: border-box;
                height: 67px;
                width: 100%;
                background: url(/src/assets/dttq.png) left top no-repeat;
                background-size: 100% 100%;
                margin: 10px 0 0 0;
                font-family: PingFangSC, PingFang SC;

                .wd {
                    p {
                        font-size: 12px;
                        font-weight: 400;
                        color: #1B2543;
                        padding: 10px 0 0 10px;
                    }

                    h4 {
                        display: flex;
                        align-items: center;
                        font-size: 22px;
                        font-family: PingFangSC, PingFang SC;
                        font-weight: 600;
                        color: #1B2543;
                        padding: 6px 0 0 8px;

                        img {
                            display: block;
                            height: 24px;
                            margin: 0 5px 0 0;
                        }
                    }
                }

                .endw {
                    padding: 20px 0 0 6px;
                    line-height: 22px;

                    p {
                        font-size: 12px;
                        font-weight: 400;
                        color: #1B2543;
                    }
                }

                .time {
                    flex: 1;

                    p {
                        text-align: right;
                        font-size: 12px;
                        font-family: PingFangSC, PingFang SC;
                        font-weight: 400;
                        color: #1B2543;
                        padding: 10px 10px 0 0;
                    }

                    h4 {
                        text-align: right;
                        font-size: 14px;
                        font-family: PingFangSC, PingFang SC;
                        font-weight: 600;
                        color: #1B2543;
                        padding: 10px 10px 0 0;
                    }
                }
            }

            .imgBox {
                padding: 10px 0;

                img {
                    display: block;
                    width: 100%;
                }
            }

            .sfxx {
                background: rgba(0, 175, 112, 0.05);
                border-radius: 2px;
                overflow: hidden;
                padding: 0 0 10px 0;

                .tastItemList {
                    li {
                        padding: 0 10px;

                        &::before {
                            content: none;
                        }
                    }
                }
            }
        }
    }
}

.tastItemList {
    display: flex;
    padding: 10px 0 0 0;
    margin: 0;

    li {
        line-height: 24px;
        color: #868686;
        font-size: 14px;
        font-family: PingFangSC, PingFang SC;
        font-weight: 500;
        flex: 1;

        &::before {
            content: '';
            display: block;
            width: 5px;
            height: 5px;
            border-radius: 50%;
            background: #999999;
            float: left;
            margin: 8px 4px 0 0;
        }

        label {
            font-size: 14px;
            font-family: PingFangSC, PingFang SC;
            font-weight: 500;
            color: #333333;
        }

        img {
            display: block;
            float: left;
            width: 16px;
            margin: 4px 5px 0 0;
        }

        .tags {
            display: inline-block;
            padding: 0 3px;
            margin: 0 0 0 2px;
            border: 1px solid #999;
            height: 20px;
            line-height: 18px;
            padding: 0 7px;
            min-width: 40px;
            text-align: center;
            border-radius: 10px;
            box-sizing: border-box;
            white-space: nowrap;
            font-size: 12px;
            &+.tags {
                margin-left: 5px;
            }
            &.EXUBERANT {
                background: #d1992520;
                border: 1px solid #d19925;
            }

            &.ROBUST {
                background: #E6F6F0;
                border: 1px solid #A7E2CC;
            }

            &.MEDIUM {
                background: #F1F8F5;
                border: 1px solid #C9E6D6;
            }

            &.BAD {
                background: #FEEFEF;
                border: 1px solid #FBBEBE;
            }
        }
    }
}
</style>